<%@ page contentType="text/html; charset=UTF-8" language="java" isErrorPage="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>查看我的发布</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
    <link rel="Shortcut Icon" href="../../images/logo.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/css/bootstrap.css">
</head>
<body>
<!-- 头部导航栏 -->
<%@ include file="../header.jsp" %>
<section class="mt-2">
    <div class="container">
        <div class="row">
            <div class="col-12">
                <div class="d-flex align-items-center p-3 my-3 text-white-50 rounded border-bottom">
                    <img class="mr-3  rounded-circle shadow" src="${sessionScope.photo}" alt="头像" width="48" height="48">
                    <div class="lh-100">
                        <h6 class="mb-0 text-muted lh-100">${nickname}</h6>
                        <small class="text-primary">@${username}</small>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <!-- 测边导航栏-->
            <div class="col-lg-2 col-md-12 ml-2">
                <p class="pl-4 d-none d-lg-block">
                    <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-person-circle mr-1"
                         fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                        <path d="M13.468 12.37C12.758 11.226 11.195 10 8 10s-4.757 1.225-5.468 2.37A6.987 6.987 0 0 0 8 15a6.987 6.987 0 0 0 5.468-2.63z"/>
                        <path fill-rule="evenodd" d="M8 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"/>
                        <path fill-rule="evenodd"
                              d="M8 1a7 7 0 1 0 0 14A7 7 0 0 0 8 1zM0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8z"/>
                    </svg>
                    用户中心
                </p>
                <ul class="nav nav-pills justify-content-center border">
                    <li class="nav-item pt-2">
                        <a class="nav-link" href="/user/update">个人信息修改</a>
                    </li>
                    <li class="nav-item pt-2">
                        <a class="nav-link" href="/user/updatephoto">头像修改</a>
                    </li>
                    <li class="nav-item pt-2">
                        <a class="nav-link" href="/user/changepassword">密码修改</a>
                    </li>
                    <li class="nav-item pt-2">
                        <a class="nav-link active"
                           href="${type == 1 ?'/cooperation/checkPublish?currentPageIndex=1' : '/activity/selectActivitiesByAid?currentPageIndex=1'} ">查看我的发布</a>
                    </li>
                    <li class="nav-item pt-2">
                        <a class="nav-link" href="/user/viewloginlog">查看登陆日志</a>
                    </li>
                </ul>
            </div>
            <div class="col-lg-9 col-md-12 ml-2">
                <p class="d-none d-lg-block">查看我的发布</p>
                <table class="table mt-4" style="text-align: center">
                    <thead>
                    <tr>
                        <th scope="col">#</th>
                        <th scope="col">发布时间</th>
                        <th scope="col">发布标题</th>
                        <th scope="col">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${resultInfo.data.list}" var="list" varStatus="s">
                        <tr>
                            <th scope="row">${s.count}</th>
                            <td>${list.publish_time}</td>
                            <td>
                                <c:if test="${type == 1}">
                                    <a href="${path}/cooperation/selectByCoid?coid=${list.coid}" style="text-decoration: none;width: 30em;overflow: hidden;text-overflow: ellipsis;">${list.title}</a></c:if>
                                <c:if test="${type == 2}">
                                    <a href="${path}/activity/selectActivityById?id=${list.activity_id}" style="text-decoration: none;width: 30em;overflow: hidden;text-overflow: ellipsis;">${list.title}</a>
                                </c:if>

                            </td>
                            <td>
                                <c:if test="${type == 1}">
                                    <c:set value="${list.coid}" var="id"></c:set>
                                </c:if>
                                <c:if test="${type == 2}">
                                    <c:set value="${list.activity_id}" var="id"></c:set>
                                </c:if>
                                <button type="button" class="btn btn-warning" style="padding: 0 0; font-size: 14px;" onclick="toAdd(${type},${id})">添加人员</button>&nbsp;
                                <button type="button" class="btn btn-primary" style="padding: 0 0; font-size: 14px;" onclick="toUpdate(${type},${id})">修改</button>&nbsp;
                                <button type="button" class="btn btn-danger" style="padding: 0 0; font-size: 14px" onclick="toDelete(${type},${id})">删除</button>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <nav aria-label="Page navigation example">
                    <ul class="pagination">
                        <%--如果页数为1 则不展示分页符--%>
                        <c:if test="${resultInfo.data.pageCount > 1}">
                            <%--上一页按钮--%>
                            <c:set var="href" value="${path}${url}currentPageIndex=${currentPageIndex - 1}"/>
                            <li class="page-item ${currentPageIndex - 1 <= 0 ? 'disabled' : ''}">
                                <a class="page-link" href="${href}" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                            <%--遍历页数--%>
                            <c:forEach begin="1" end="${resultInfo.data.pageCount}" var="pageIndex">
                                <c:set var="href"
                                       value="${path}${url}currentPageIndex=${pageIndex}"/>
                                <li class="page-item ${currentPageIndex == pageIndex ? 'active' : ''}"><a
                                        class="page-link" href="${href}">${pageIndex}</a></li>
                            </c:forEach>
                            <%--下一页按钮--%>
                            <c:set var="href" value="${path}${url}currentPageIndex=${currentPageIndex + 1}"/>
                            <li class="page-item ${currentPageIndex + 1 > resultInfo.data.pageCount ? 'disabled' : ''}">
                                <a class="page-link" href="${href}" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        </c:if>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</section>


<!--引入JQuery,再引入popper.js，最后引入bootstrap.js-->
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.bundle.js"></script>
<script>
    // 更新按钮触发事件
    function toUpdate(type,id) {
            if(type == 1){
                location.href = '/cooperation/preUpdate?coid='+ id;
            }
            if(type == 2){
                location.href='/activity/updateActivity?id='+ id;
            }
    }

    // 删除按钮触发事件
    function toDelete(type,iid) {
        //提示删除提示
        if (confirm("您确定删除吗？")) {
            //访问路径
            if(type == 1){
                location.href = "/cooperation/delete?coid=" + iid;
            }
            if(type == 2){
                location.href = "/activity/delete?id=" + iid;
            }
        }
    }

    //添加人员按钮触发事件
    function toAdd(type,id) {
        const name = prompt("请填写您队员的username：", "");
        if (name!=null && name!="") {
            if (type == 1){
                $.ajax({
                    type:"GET",
                    url:"/cooperation/updatePopulation?coid=" + id + "&username=" + name,
                    dataType:"json",
                    success:function(e){
                        alert(e.message);
                    }
                });
            } if (type == 2){
                $.ajax({
                    type:"GET",
                    url:"/activity/choose?id=" + id + "&username=" + name,
                    dataType:"json",
                    success:function(e){
                        alert(e.message);
                    }
                });
            }

        }

    }
</script>
<script src="/js/message.js"></script>

</body>
</html>